package javabasic.threads.getsubthreadvalue;

public class LoopGet {
    public static void main(String[] args) {
        GetSub02 getSub02 = new GetSub02();
        Thread thread = new Thread(getSub02);
        thread.start();
        while (getSub02.str1==null){
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("主线程中拿到子线程的值："+getSub02.str1);
    }
}

class GetSub02 implements Runnable{
    String str1;
    @Override
    public void run() {
        try {
            Thread.sleep(100);
            str1="sub thread value";
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}